Skip to content

fix: HybridFs subclass, Prettier template literal fixes, path normali…#134

Merged
simongdavies merged 6 commits into
hyperlight-dev:mainfrom
simongdavies:feat-execute-bash
May 14, 2026
Merged

fix: HybridFs subclass, Prettier template literal fixes, path normali…#134
simongdavies merged 6 commits into
hyperlight-dev:mainfrom
simongdavies:feat-execute-bash

Conversation

@simongdavies
Copy link
Copy Markdown
Member

@simongdavies simongdavies commented May 14, 2026

This pull request refactors and improves the src/agent/index.ts codebase, focusing on simplifying string formatting (moving from template literals to string concatenation), enhancing the construction of the bash runner handler, and improving the hybrid filesystem adapter logic. The changes aim to make the code more robust, maintainable, and less error-prone, especially in areas involving code generation and file system operations.

Key changes include:

String Formatting and Logging Consistency

  • Replaced most template literals with string concatenation for log messages and command outputs throughout src/agent/index.ts, improving compatibility and reducing parsing errors during code generation.

Bash Runner Handler and Filesystem Adapter Refactor

  • Refactored the construction of the hybrid hostFs filesystem adapter to use a class-based approach (HybridFs extends InMemoryFs) with string concatenation, improving clarity and maintainability. Added a normPath helper to sanitize paths before delegating to plugins.
  • Reworked the generation of the bash runner handler code to use explicit string concatenation, reducing the risk of issues with nested template literals and making the generated code easier to reason about.

Bash and Command Handler Improvements

  • Improved the logic for determining and displaying available commands, including better handling of the curl command and clearer help output.
  • Enhanced the construction of bash handler options using string concatenation for consistency and maintainability.

Minor Functional Improvements

  • Updated the curl command to prepend https:// only if the URL does not already contain a protocol, making it more robust.
  • Improved warning handling in the native DTS generator to silently skip modules that only register globals.

These changes collectively improve the maintainability and robustness of the code, especially in areas where code is dynamically generated or where string formatting is critical for correctness.

…sation

- Refactor bash FS adapter from plain object to HybridFs extends InMemoryFs
  (cleaner, uses super.method() fallbacks instead of delegating 12 methods)
- Add normPath() to strip /home/user/ and /tmp/ prefixes from bash paths
- Replace nested template literals inside C.dim/C.err/C.ok/C.warn with
  string concatenation to prevent Prettier mangling
- Use url.indexOf instead of regex for curl URL scheme detection
- Silence spurious warning for native-globals module in generate-native-dts
- Add prettier-ignore for help command template literal
- Null-safe result.error in reset_sandbox handler

Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com>
- Add large output interception to execute_bash handler (mirrors
  execute_javascript pattern) — saves results to disk before the SDK
  can truncate to inaccessible host /tmp files
- Fix normPath in HybridFs: /tmp/foo.txt now maps to tmp/foo.txt
  (not foo.txt) preventing file collisions with user files in baseDir
- Add HOST FILESYSTEM warning to system message so LLM knows /tmp
  paths are not accessible from the sandbox
- Add /tmp inaccessibility note to execute_bash tool description

Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 14, 2026 08:17
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR integrates a sandboxed Bash execution path into HyperAgent (via the new execute_bash tool and a dedicated bash sandbox), along with associated build/lockfile updates and some formatting-oriented refactors to avoid Prettier/template-literal parsing issues.

Changes:

  • Refactors bash runner handler generation (HybridFs adapter + handler code assembly) and replaces some nested template literals with string concatenation in src/agent/index.ts.
  • Adjusts native .d.ts generation script behavior for modules without #[rquickjs::function].
  • Updates dependency lockfiles (npm + Rust guest).

Reviewed changes

Copilot reviewed 2 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/code-validator/guest/Cargo.lock Rust dependency lockfile drift (tokio patch version change).
src/agent/index.ts Bash sandbox/tool wiring plus HybridFs adapter refactor and string-concat formatting changes.
scripts/generate-native-dts.ts Changes behavior when no Rust-exported functions are detected (now skips silently).
package-lock.json NPM dependency resolution updates (including several version downgrades and an altered @types/node entry).
Comments suppressed due to low confidence (2)

src/agent/index.ts:2316

  • HybridFs.readdir assumes fsRead.listDir returns an object with an entries array, but the fs-read plugin returns either a DirEntry[] array or { error }. This will throw at runtime (r.entries is undefined) and break ls/find/tree when fs-read is enabled. Update this branch to handle the actual return shape (e.g. if Array.isArray(r) map name, otherwise throw/fallback on r.error).
      "  async readdir(path) {",
      "    try { const r = fsRead.listDir(normPath(path)); if (r.error) throw new Error(r.error); return r.entries.map(e => e.name); }",
      "    catch { return super.readdir(path); }",

src/agent/index.ts:2340

  • HybridFs.mkdir calls fsWrite.mkdir() but ignores its { ok, error } return value. Since fs-write reports failures via error (it generally does not throw), bash mkdir can report success even though the directory was rejected/failed to create. Capture the return value and throw/fallback when error is set (similar to writeFile/appendFile).
      "  async mkdir(path, opts) {",
      "    try { fsWrite.mkdir(normPath(path)); }",
      "    catch { await super.mkdir(path, opts); }",
      "  }",

Comment thread src/agent/index.ts Outdated
Comment thread src/agent/index.ts Outdated
Comment thread scripts/generate-native-dts.ts Outdated
- Fix HybridFs.stat: use r.isFile/r.isDirectory instead of r.type
  (fs-read plugin returns {isFile, isDirectory, size, error}, not type/modified)
- Fix normPath: segment-based normalizer that handles ../a/../b, bare ..,
  and Windows backslashes; throws on virtual root escape attempts
- Fix generate-native-dts: only skip native-globals silently; warn for
  other modules with no #[rquickjs::function] exports

Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 5 changed files in this pull request and generated 4 comments.

Comment thread src/agent/index.ts Outdated
Comment thread src/agent/index.ts Outdated
Comment thread src/agent/index.ts Outdated
Comment thread src/agent/system-message.ts Outdated
- readdir: handle listDir() returning DirEntry[] directly (not r.entries)
- mkdir: capture return value, throw on r.error instead of ignoring
- large output: check threshold BEFORE printing stdout to avoid console flood
- system message: qualify that auto-save to results/ requires fs-write enabled

Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com>
@simongdavies simongdavies merged commit 4131af4 into hyperlight-dev:main May 14, 2026
12 checks passed
simongdavies added a commit that referenced this pull request May 15, 2026
* docs: changelog for v0.6.0

Move [Unreleased] section to [v0.6.0] - 2026-05-15 covering the 23
commits landed on upstream/main since v0.5.0:

Added:
- User-generated skills from session learnings (#139)
- KQL expert skill with requires-mcp frontmatter and Kusto highlighting (#137)
- Terminal markdown rendering via marked + marked-terminal (#135, #136)
- Verbose/debug gating for diagnostic output (#137)
- execute_bash large output interception (#134)

Fixed:
- marked v15 + marked-terminal v7 incompat in markdown-renderer (#138)
- HybridFs sandbox /tmp path mapping + adapter refactor (#134)
- Prettier mangling of nested template literals in styled output (#134)
- Full error text now wrapped in C.err() across 11 paths (#135)
- /markdown toggle now flips sessionNeedsRebuild (#136)
- looksLikeMarkdown false positives on bold/unordered-list (#136)

Changed:
- Dependency bumps: msal-node 5.2.1, tsx 4.22.0, @types/node 25.8.0,
  tokio in code-validator guest (#142, #143, #146, #147)

Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com>

* fix: address PR #148 review feedback (3 issues)

CHANGELOG.md:
- Fabric RTI CLI flag: `--mcp setup-fabric-rti` was wrong, actual
  flag in src/agent/cli-parser.ts is `--mcp-setup-fabric-rti`
  (single hyphenated token). Users copy-pasting the old form would
  hit "unknown argument"
- Terminal markdown rendering default: said "raw streaming remains
  the default" but cli-parser.ts sets `markdown: process.env.HYPERAGENT_MARKDOWN
  !== "0"` (default ON) and `--[no-]markdown` help text confirms
  default: on. Reworded to make default-on explicit and document
  the three opt-out paths
- Missing link reference: added
  `[v0.6.0]: https://github.com/hyperlight-dev/hyperagent/releases/tag/v0.6.0`
  to match the existing reference-style link section

No code changes. Prettier clean.

Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com>

---------

Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants